<div class="breadcrumbs">
    <a href="http://anhhanquoc.hehe.vn">Tạo ảnh Hàn Quốc</a> › Bước cuối
</div>
<br>
<h2>OK! Bây giờ bạn chọn vùng ảnh và cắt nhé</h2>
<hr>
<br>
<script src="/js/jcrop/js/jquery.Jcrop.js"></script>
<link rel="stylesheet" href="/js/jcrop/css/jquery.Jcrop.css" type="text/css" />
<script language="Javascript">
$(function(){
<?php foreach($uploads as $i => $upload):?>
    $('#cropbox<?php echo $i?>').Jcrop({
        aspectRatio: <?php echo $upload->min_wh['w']?> / <?php echo $upload->min_wh['h']?>,
        minSize : [<?php echo $upload->min_wh['w']?>, <?php echo $upload->min_wh['h']?>],
        maxSize : [<?php echo $upload->image_dst_x?>, <?php echo $upload->image_dst_y?>],
        setSelect : [100, 100, <?php echo $upload->min_wh['w']?>, <?php echo $upload->min_wh['h']?>],
        onSelect: updateCoords<?php echo $i?>
    });
<?php endforeach;?>
});

<?php foreach($uploads as $i => $upload):?>
function updateCoords<?php echo $i?>(c){
    $('#x<?php echo $i?>').val(c.x);
    $('#y<?php echo $i?>').val(c.y);
    $('#w<?php echo $i?>').val(c.w);
    $('#h<?php echo $i?>').val(c.h);
};
<?php endforeach;?>

</script>

<?php foreach($uploads as $i => $upload):?>
<h3>Hình <?php echo $i+1?></h3>
<img src="/<?php echo $upload->image?>" id="cropbox<?php echo $i?>" />
<hr>
<br>
<?php endforeach;?>
<br>

<form method="post">
<?php foreach($uploads as $i => $upload):?>
    <input type="hidden" id="x<?php echo $i?>" name="x[<?php echo $i?>]" />
    <input type="hidden" id="y<?php echo $i?>" name="y[<?php echo $i?>]" />
    <input type="hidden" id="w<?php echo $i?>" name="w[<?php echo $i?>]" />
    <input type="hidden" id="h<?php echo $i?>" name="h[<?php echo $i?>]" />
    <input type="hidden" name="image[<?php echo $i?>]" value="<?php echo $upload->image?>" />
    <input type="hidden" name="image_w[<?php echo $i?>]" value="<?php echo $upload->image_dst_x?>" />
    <input type="hidden" name="image_h[<?php echo $i?>]" value="<?php echo $upload->image_dst_y?>" />
<?php endforeach;?>

    
    
    <center>
    <input type="text" name="title" placeholder="Tên ảnh" style="width: 200px;">
    <button id="crop2" name="crop2" value="crop2" type="submit">OK! Cắt ảnh nào</button>
    </center>
</form>

<div id="loading" style="width: 100%; text-align: center; display: none;">
<br>
<img src="/files/images/loader.gif"><br>
Hệ thống đang cắt ảnh và xử lý các bước cuối cùng
</div>


<script>
FB.Event.subscribe('edge.remove',function() {window.location.reload();});
$(function(){
    $('#crop2').click(function(){
<?php foreach($uploads as $i => $upload):?>
        if(!parseInt($('#w<?php echo $i?>').val())){
            alert('Bạn cần chọn vùng cắt cho ảnh thứ <?php echo $i+1?> trước khi cắt ảnh.');
            return false;
        }
<?php endforeach;?>  
        $('#loading').fadeIn('fast');     
    });
})
</script>
